<template>
  <div class="bigbox">
    <van-nav-bar @click-left="$router.back()">
      <template #left>
        <van-icon name="arrow-left" size="20" color="black" />
        返回
      </template>
      <template #title> 填写订单 </template>
    </van-nav-bar>

    <div class="main">
      <van-contact-card
        type="edit"
        :name="currentContact.name"
        :tel="currentContact.tel"
        @click="onEdit"
      />

      <van-field is-link label="地址" :placeholder="text" @click="show" />

      <div class="goods" v-for="(item, index) in orderlist" :key="index">
        <van-card
          :num="item.num"
          :price="item.originprice"
          :title="item.proname"
          :thumb="item.img1"
        />
      </div>
    </div>
    <van-submit-bar
      :price="price * 100"
      button-text="提交订单"
      @submit="onSubmit"
    />
  </div>
</template>

<script>
import Vue from "vue";
import {
  ContactCard,
  Card,
  GoodsAction,
  GoodsActionButton,
  GoodsActionIcon,
  Toast,
  Cascader,
  SubmitBar,
} from "vant";
Vue.use(GoodsAction);
Vue.use(GoodsActionButton);
Vue.use(GoodsActionIcon);
Vue.use(ContactCard);
Vue.use(Card);
Vue.use(Toast);
Vue.use(Cascader);
Vue.use(SubmitBar);
// Vue.use(Collapse);
// Vue.use(CollapseItem);
import { ConfirmOrder } from "../api/order";
import { defaultAddress } from "../api/massage";
export default {
  data() {
    return {
      currentContact: {
        name: "请选择",
        tel: "请选择",
      },
      text: "请选择",
      orderlist: [],
      price: null,
      show1: false,
    };
  },
  methods: {
    onEdit() {
      this.$router.push("/massage");
    },
    onSubmit() {
      // console.log(this.$route.params.time);
      this.$router.push("/pay/" + this.price);
    },
    show() {
      this.$router.push("/massage");
    },
    showPopup() {
      this.show1 = true;
    },
  },
  created() {
    defaultAddress({ userid: localStorage.getItem("userid") }).then((data) => {
      //查看默认信息
      console.log(data.data.data[0]);
      data.data.data.forEach((item) => {
        this.currentContact = {
          name: item.name,
          tel: item.tel,
        };
      });
      this.text =
        data.data.data[0].province +
        "" +
        data.data.data[0].city +
        "" +
        data.data.data[0].county;
    });
    console.log(this.$route.params.time);
    ConfirmOrder({
      userid: localStorage.getItem("userid"),
      time: this.$route.params.time,
    }).then((data) => {
      //确认订单信息
      console.log(data);
      this.orderlist = data.data.data;
      this.price = this.orderlist.reduce((sum, item) => {
        return (sum = sum + item.originprice * item.num);
      }, 0);
      console.log(this.price);
    });
  },
};
</script>

<style scoped>
.main {
  overflow: auto;
}
.none {
  height: 44px;
}
/* .bigbox{
    display: flex;
} */
</style>